package com.yida.system.api.domain;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;

import com.alibaba.fastjson2.annotation.JSONField;
import com.yida.common.core.web.domain.BaseEntity;
import com.yida.common.core.xss.Xss;

/**
 * 用户对象 sys_user_ukey
 *
 * @author yida
 */
public class SysUserUkey extends BaseEntity {
    private static final long serialVersionUID = 1L;

    /**
     * id主键
     */
    private Long id;

    /**
     * 用户ID
     */
    private Long userId;

    /**
     * 用户账号
     */
    private String userName;

    /**
     * 密码
     */
    @JSONField(serialize = false)
    private String password;

    /**
     * Ukey pin码
     */
    private String pin;

    /**
     * 国密私钥
     */
    private String priKey;

    /**
     * 国密公钥X
     */
    private String pubKeyX;

    /**
     * 国密公钥Y
     */
    private String pubKeyY;

    /**
     * Ukey id
     */
    private String ukeyId;

    /**
     * 待加签内容
     */
    @JSONField(serialize = false)
    private String rnd;

    /**
     * 待验Ukey加密串
     */
    @JSONField(serialize = false)
    private String signUKeyStr;

    /**
     * 状态：0启用;1未启用；
     */
    @JSONField(serialize = false)
    private Integer status;

    /**
     * 区域ID
     */
    private Long areaId;

    /** 备注 */
    private String remark;

    public SysUserUkey() {

    }

    public SysUserUkey(String pin, String rnd) {
        this.pin = pin;
        this.rnd = rnd;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public SysUserUkey(Long userId) {
        this.userId = userId;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public boolean isAdmin() {
        return isAdmin(this.userId);
    }

    public static boolean isAdmin(Long userId) {
        return userId != null && 1L == userId;
    }

    @Xss(message = "用户账号不能包含脚本字符")
    @NotBlank(message = "用户账号不能为空")
    @Size(min = 0, max = 30, message = "用户账号长度不能超过30个字符")
    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setPin(String pin) {
        this.pin = pin;
    }

    @Xss(message = "设备PIN编码有误")
    @NotBlank(message = "PIN不能为空")
    public String getPin() {
        return pin;
    }

    public String getPriKey() {
        return priKey;
    }

    public void setPriKey(String priKey) {
        this.priKey = priKey;
    }

    public String getPubKeyX() {
        return pubKeyX;
    }

    public void setPubKeyX(String pubKeyX) {
        this.pubKeyX = pubKeyX;
    }

    public String getPubKeyY() {
        return pubKeyY;
    }

    public void setPubKeyY(String pubKeyY) {
        this.pubKeyY = pubKeyY;
    }

    @Xss(message = "设备UKeyId编码有误")
    @NotBlank(message = "UKeyId不能为空")
    public String getUkeyId() {
        return ukeyId;
    }

    public void setUkeyId(String ukeyId) {
        this.ukeyId = ukeyId;
    }

    public String getRnd() {
        return rnd;
    }

    public void setRnd(String rnd) {
        this.rnd = rnd;
    }

    @NotBlank(message = "signUKeyStr待签串不能为空")
    public String getSignUKeyStr() {
        return signUKeyStr;
    }

    public void setSignUKeyStr(String signUKeyStr) {
        this.signUKeyStr = signUKeyStr;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public Long getAreaId() {
        return areaId;
    }

    public void setAreaId(Long areaId) {
        this.areaId = areaId;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("SysUser{");
        sb.append("userId=").append(userId);
        sb.append(", userName='").append(userName).append('\'');
        sb.append(", password='").append(password).append('\'');
        sb.append(", pin='").append(pin).append('\'');
        sb.append(", signUKeyStr='").append(signUKeyStr).append('\'');
        sb.append('}');
        return sb.toString();
    }
}
